package com.rikao.service;

import com.rikao.dao.EmpDao;
import com.rikao.pojo.Emp;
import org.springframework.stereotype.Service;
import utils.IdWorker;

import javax.annotation.Resource;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class EmpService {
    @Resource
    private EmpDao empDao;
    @Resource
    private IdWorker idWorker;

    //模糊查询
    public List<Emp> findlike(String adress){

        adress = "%"+adress+"%";
        List list=empDao.findByAdressLike(adress);

        return list;
    }

    //增加
    public void add(Emp emp){

        emp.setId(idWorker.nextId()+"");

        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-DD hh:mm:ss");
        String format = sdf.format(date);
        emp.setStartdate(format);

        empDao.save(emp);
    }

    //删除
    public void deletes(String id){

        empDao.deleteById(id);
    }

    //查询
    public List<Emp> findAll(){
        List<Emp> empList = empDao.findAll();
        return empList;
    }
}
